package com.original.simuladores.service.impl;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.original.simuladores.dao.ProductDao;
import com.original.simuladores.entities.Product;
import com.original.simuladores.service.ProductService;

public class ProductServiceImpl implements ProductService {
	
	@Autowired
	ProductDao productDao;

	@Override
	public List<Product> getProductById(Integer id) {
		return productDao.read(Product.class, id);
	}

	@Override
	public List<Product> getProducts() {
		return productDao.read(Product.class);
	}

	@Override
	public int create(Product prt) {
		return (Integer) productDao.create(prt);
	}

	@Override
	public int delete(Product prt) {
		return (Integer) productDao.delete(Product.class, prt.getId());
	}

	@Override
	public int update(Product prt) {
		// TODO Auto-generated method stub
		return (Integer) productDao.update(prt);
	}

	@Override
	public Integer getId() {
		List<Product> ls = productDao.lastestObject(Product.class);
		Integer idReturn = 1;
		if (ls != null && ls.size() > 0) {
			Product obj = ls.get(0);
			idReturn = obj.getId()  + 1;
		}
		return idReturn;
	}
}
